<template>
  <div class="zhebi">
    <div class="danwei">
      <div class="danwei-header">
        <div class="cancel" @click="danWeiCancel">取消</div>
        <div class="title">按单位筛选</div>
        <div class="yes" @click="danWeiYes">确定</div>
      </div>
      <div class="danwei-body">
        <div>
          <div :class="classArray" v-for="(item,index) in pdaoList" :id="index" :key="index" @click="selectThis(index,item.companyName)" :ref="listDom">{{item.companyName}}</div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { useStore } from 'vuex'
import { reactive, ref } from 'vue'
export default {
  emits: ['emitDanwei', 'emitGetSearch'],
  setup(props, ctx) {
    const store = useStore()
    const pdaoList = store.state.pinDaoList.data
    const classArray = { item: true, current: false }
    const pingDaoId = ref('')
    const danWeiCancel = () => {
      ctx.emit('emitDanwei', false)
    }
    const danWeiYes = () => {
      ctx.emit('emitGetSearch', pingDaoId.value)
    }
    let resultList = []
    const listDom = (e) => {
      resultList.push(e)
    }

    const selectThis = (e,companyName) => {
      for (let i = 0; i < resultList.length; i++) {
        if (resultList[i].id == e) {
          resultList[i].className = 'item current'
          pingDaoId.value = companyName
        } else {
          resultList[i].className = 'item'
        }
      }
    }

    return {
      danWeiCancel,
      danWeiYes,
      classArray,
      selectThis,
      listDom,
      pdaoList
    }
  }
}
</script>
<style scoped>
.zhebi {
  background: rgba(0, 0, 0, 0.8);
  height: 100%;
  width: 100%;
  position: fixed;
  left: 0;
  top: 0;
}
.danwei {
  min-height: 100px;
  width: 80%;
  background: #fdc830;
  border-radius: 10px;
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  top: 15%;
}
.danwei .danwei-header {
  display: flex;
  height: 46px;
  justify-content: space-between;
  border-bottom: 1px solid #f2d78b;
  line-height: 46px;
}
.danwei .danwei-header .cancel {
  text-align: center;
  padding-left: 15px;
  color: #715915;
}
.danwei .danwei-header .yes {
  text-align: center;
  padding-right: 15px;
  color: #ff4a4a;
}
.danwei .danwei-header .title {
  color: black;
  font-weight: bold;
}
.danwei .danwei-body {
  height: 200px;
  overflow-y: auto;
}
.danwei .danwei-body .item {
  padding: 8px 0;
  color: #b18c22;
  text-align: center;
}
.danwei .danwei-body .current {
  color: black;
  background: linear-gradient(to left, transparent, white, transparent);
}
</style>
